package javadoc;

import com.github.javaparser.JavaParser;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.ast.visitor.VoidVisitorAdapter;
import com.google.common.base.Strings;

import java.io.File;
import java.io.IOException;

public class MethodCallsExample {

    public static void listMethodCalls(File projectDir) {
        new DirExplorer((level, path, file) -> path.endsWith(".java"), MethodCallsExample::handle).explore(projectDir);
    }

    public static void main(String[] args) {
        File projectDir = new File("apigenerator/dto");
        listMethodCalls(projectDir);
    }

    private static void handle(int level, String path, File file) {
        System.out.println(path);
        System.out.println(Strings.repeat("=", path.length()));
        try {
            new VoidVisitorAdapter<Object>() {
                @Override public void visit(MethodCallExpr n, Object arg) {
                    super.visit(n, arg);
                    System.out.println(" [L " + n.getBegin().get().line + "] " + n);
                }
            }.visit(StaticJavaParser.parse(file), null);
            System.out.println(); // empty line
        } catch (IOException e) {
            new RuntimeException(e);
        }
    }
}